﻿

using HBase;
 
using MongoDB.Bson;
using Net.http;
using System; 
using System.Net; 

namespace WebApi {
   
    [RoutePrefix("log")]
    public class LoggerController :BaseApiController {



        IMServer MGStatuslog = GuidangFactray.getDal<IMServer>();
        [HttpGet, Route("tables")]
        public BaseResult tables() {
            var tables = ConnectionCache.queryTables();
            return BaseResult.Ok(tables);
        }


       

        [HttpGet, Route("all/{pageSize}/{name}/{begin}/{field}/{type}/{v}")]
        public BaseResult showEquipment(String name ,int begin ,int pageSize,string field ,String type ,string v) {

            v = WebUtility.UrlDecode(v);

            BsonDocument query = new BsonDocument();
      
            if( !String.IsNullOrEmpty(field) && !String.IsNullOrEmpty(v) ) {
                if( type == "like" ) {
                    query[field] = new BsonRegularExpression("/" + v + "/");
                } else if( type == "eq" ) {
                    int vl = 0;
                    if (int.TryParse(v, out vl)) {
                        query[field] = vl;
                    } else {
                        query[field] = v;
                    }
                
                   
                } else if( type == "gte" ) {

                    query[field] = new BsonDocument();

                    int vl = 0;
                    if (int.TryParse(v, out vl)) {
                        query[field]["$gte"] = vl;
                    } else {
                        query[field]["$gte"] = v;
                    }

                  
                    
                } else if( type == "lte" ) {
                    int vl = 0;
                    if (int.TryParse(v, out vl)) {
                        query[field]["$lte"] = vl;
                    } else {
                        query[field]["$lte"] = v;
                    } 
                }


            }
            Page<Object> info = MGStatuslog.queryPage(name ,begin, pageSize, query);
            return BaseResult.Ok(info);
        }


 
        [HttpPost, Route("wcsFindEquipmentPage")]
        public BaseResult wcsFindEquipmentPage([FromBody] MessageDto dto) {
            String name =  dto.tableName;
            if (String.IsNullOrWhiteSpace(name)) {
                return BaseResult.Error("输入集合名称");
            }
            var info = MGStatuslog.queryPage(name ,dto);
            return BaseResult.Ok(info);
        }
        [HttpGet, Route("showEquipment/{id}")]
        public BaseResult showEquipment(String id) {
            Object info = MGStatuslog.show("status" ,id);
            return BaseResult.Ok(info);
        }
   
    }
}
